//
//  DDRTSelectedMemberTableCell.m
//  DDRichTextDemo
//
//  Created by 张小伟 on 2021/9/19.
//

#import "DDRTSelectedMemberTableCell.h"
#import "DDRTHeader.h"

@interface DDRTSelectedMemberTableCell ()

@property(nonatomic,strong)UIView *superAllView;

@property(nonatomic,strong)UILabel *leftLabel;

@property(nonatomic,strong)UIView *lineView;

@property(nonatomic,strong)UIButton *selectedBtn;

@end

@implementation DDRTSelectedMemberTableCell

+(instancetype)updateWithTableView:(UITableView *)tableView {
    
    static NSString *ID = @"kDDRTSelectedMemberTableCellId";
    DDRTSelectedMemberTableCell *cell = [tableView dequeueReusableCellWithIdentifier:ID];
    if (!cell) {
        cell = [[DDRTSelectedMemberTableCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:ID];
    }
    return cell;
}

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        
        [self.contentView addSubview:self.superAllView];
        [self.superAllView addSubview:self.leftLabel];
        [self.superAllView addSubview:self.lineView];
        [self.superAllView addSubview:self.selectedBtn];
        
        [self.superAllView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.contentView).with.offset(0);
            make.right.equalTo(self.contentView).with.offset(-0);
            make.top.equalTo(self.contentView).with.offset(0);
            make.bottom.equalTo(self.contentView).with.offset(0);
        }];

        [self.leftLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.superAllView).with.offset(15);
            make.top.bottom.equalTo(self.superAllView).with.offset(0);
            make.width.mas_equalTo(@100);
        }];

        [self.lineView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.superAllView).with.offset(15);
            make.right.equalTo(self.superAllView).with.offset(-15);
            make.bottom.equalTo(self.superAllView).with.offset(-1);
            make.height.equalTo(@1.0);
        }];

        [self.selectedBtn mas_makeConstraints:^(MASConstraintMaker *make) {
            make.right.equalTo(self.superAllView).with.offset(- 15);
            make.centerY.equalTo(self.superAllView).with.offset(0);
            make.size.mas_equalTo(CGSizeMake(30, 30));
        }];
        
//        self.backgroundColor = RGB(238, 238, 244);
        
    }
    return self;
}
-(void)setGroupMemberModel:(DDRTGroupMemberModel *)groupMemberModel {
    _groupMemberModel = groupMemberModel;
    self.leftLabel.text = groupMemberModel.personName;
    self.selectedBtn.selected = groupMemberModel.isSelected;
}



-(UIView *)superAllView {
    if (!_superAllView) {
        _superAllView = [[UIView alloc] init];
        _superAllView.backgroundColor = [UIColor whiteColor];
    }
    return _superAllView;
}
-(UILabel *)leftLabel {
    if (!_leftLabel) {
        _leftLabel = [[UILabel alloc] init];
        _leftLabel.font = [UIFont systemFontOfSize:18];
        _leftLabel.textColor = [UIColor redColor];
        _leftLabel.textAlignment = NSTextAlignmentLeft;
    }
    return _leftLabel;
}

-(UIView *)lineView {
    if (!_lineView) {
        _lineView = [[UIView alloc] init];
        _lineView.backgroundColor = [UIColor lightGrayColor];
    }
    return _lineView;
}

-(UIButton *)selectedBtn {
    if (!_selectedBtn) {
        _selectedBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        _selectedBtn.userInteractionEnabled = NO;
        [_selectedBtn setImage:[UIImage imageNamed:@"check_box_normal"] forState:UIControlStateNormal];
        [_selectedBtn setImage:[UIImage imageNamed:@"check_box_selected"] forState:UIControlStateSelected];
        _selectedBtn.titleLabel.font = [UIFont systemFontOfSize:14];
        _selectedBtn.layer.cornerRadius = 15;
        _selectedBtn.layer.masksToBounds = YES;
    }
    return _selectedBtn;
}


@end
